//泛型接口  在定义接口时  为接口的属性或方法定义泛型类型 在使用接口时 在指定泛型类型
(()=>{
    class User{
        id?:number
        name:string
        age:number
        constructor(name:string,age:number){
            this.name = name
            this.age = age
        }
    }
    interface IBaseCRUD<T> {
        data:Array<T>
        add:(t:T)=>T
        getUserId:(id:number)=>T
    }
    class UserCRUD implements IBaseCRUD<User>{
        data:Array<User>=[]
        add(user:User):User {
            user.id= Date.now()+Math.random()
            this.data.push(user)
            return user
            
        }
        getUserId(id:number):User {
            return this.data.find(user=>user.id===id)
        }
    }
    const userCRUD = new UserCRUD()
    userCRUD.add(new User('jack',18))
    const {id} = userCRUD.add(new User('rock',20))
    const user = userCRUD.getUserId(id)
    console.log(user);
    
})()